package com.cf.data;


import com.cf.data.serve.environment.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author cuixi
 * @description: 随主程序启动而启动 顺序为1
 * @date 2024/7/24
 */
@Component
@Order(value = 1)
@Slf4j
public class InitRunner implements ApplicationRunner {


    /**
     * 判断IP地址的合法性，这里采用了正则表达式的方法来判断 return true，合法
     */
    public static boolean ipCheck(String text) {
        if (text != null && !text.isEmpty()) {
            // 定义正则表达式
            String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
                    + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                    + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
            // 判断ip地址是否与正则表达式匹配
            if (text.matches(regex)) {
                // 返回判断信息
                return true;
            } else {
                // 返回判断信息
                return false;
            }
        }
        return false;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {

        //扬尘
        MyThread2 thread2 = new MyThread2();
        thread2.start();  // 启动线程
        MyThread thread = new MyThread();
        thread.start();  // 启动线程

/*        //水电表
        MyThread3 thread3 = new MyThread3();
        thread3.start();  // 启动线程
        MyThread4 thread4 = new MyThread4();
        thread4.start();  // 启动线程*/

        //临边防护
        MyThread5 thread5 = new MyThread5();
        thread5.start();  // 启动线程

        //深基坑
        MyThread6 thread6 = new MyThread6();
        thread6.start();  // 启动线程
    }
    class MyThread extends Thread {
        public void run() {
            TCPServer_yc c = new TCPServer_yc();
            try {
                c.yc(8335);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread is running...");
        }
    }

    class MyThread2 extends Thread {
        public void run() {
            TCPServer s = new TCPServer();
            try {
                s.jc(8334);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("Thread is running...");
        }
    }

    class MyThread3 extends Thread {
        public void run() {
            TCPServer_sb s = new TCPServer_sb();
            try {
                s.sb();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("Thread is running...");
        }
    }

    class MyThread4 extends Thread {
        public void run() {
            TCPServer_db s = new TCPServer_db();
            try {
                s.db();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("Thread is running...");
        }
    }

    class MyThread5 extends Thread {
        public void run() {
            TCPServer_lbfh s = new TCPServer_lbfh();
            try {
                s.lbsjk(8339);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("Thread is running...");
        }
    }

    class MyThread6 extends Thread {
        public void run() {
            TCPServer_lbsjk s = new TCPServer_lbsjk();
            try {
                s.lbsjk(8338);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("Thread is running...");
        }
    }
}
